package org.changchen.fgt.config;

import java.net.Inet4Address;
import java.net.InetAddress;

import org.changchen.fgt.utils.SystemUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**   
* @ClassName:  BrowerCommandRunner   
* @Description:容器启动后自动打开浏览器访问   
* @author:     ChangChen 
* @date:       2024-01-11 09:30
* @Copyright:  2024 ChangChen. All rights reserved. 
*/
@Component
public class BrowerCommandRunner implements CommandLineRunner{
	
	
	@Value("${server.port}")
	private String port;
	

	@Override
	public void run(String... args) throws Exception {
		
		InetAddress localhost = Inet4Address.getLocalHost();
		String url = "http://" + localhost.getHostAddress() + ":" + port + "/";
		
		// Windows 打开浏览器访问
		if(SystemUtil.isWindows()) {
			Runtime.getRuntime().exec("cmd /c start " + url);	
		}
		
		// 提示
		Thread.sleep(2000);
		System.out.println("\033[32;4m" + "\n（*⌒ヮ⌒*）分（*⌒ヮ⌒*）割（*⌒ヮ⌒*）线（*⌒ヮ⌒*）\n" + "\033[0m");
		System.out.println("       " + url);
		System.out.println("\033[32;4m" + "\n（*⌒ヮ⌒*）分（*⌒ヮ⌒*）割（*⌒ヮ⌒*）线（*⌒ヮ⌒*）" + "\033[0m");
	}

}
